home *** CD-ROM | disk | FTP | other *** search
/ Mac Format 1995 June / MacFormat 25.iso / Shareware City / Developers / OutOfPhase1.1 Source / OutOfPhase Folder / LFOListSpecifier.c < prev    next >
Text File  |  1994-08-15  |  4KB  |  121 lines

  1. /* LFOListSpecifier.c */
  2. /*****************************************************************************/
  3. /*                                                                           */
  4. /*    Out Of Phase:  Digital Music Synthesis on General Purpose Computers    */
  5. /*    Copyright (C) 1994  Thomas R. Lawrence                                 */
  6. /*                                                                           */
  7. /*    This program is free software; you can redistribute it and/or modify   */
  8. /*    it under the terms of the GNU General Public License as published by   */
  9. /*    the Free Software Foundation; either version 2 of the License, or      */
  10. /*    (at your option) any later version.                                    */
  11. /*                                                                           */
  12. /*    This program is distributed in the hope that it will be useful,        */
  13. /*    but WITHOUT ANY WARRANTY; without even the implied warranty of         */
  14. /*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          */
  15. /*    GNU General Public License for more details.                           */
  16. /*                                                                           */
  17. /*    You should have received a copy of the GNU General Public License      */
  18. /*    along with this program; if not, write to the Free Software            */
  19. /*    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.              */
  20. /*                                                                           */
  21. /*    Thomas R. Lawrence can be reached at tomlaw@world.std.com.             */
  22. /*                                                                           */
  23. /*****************************************************************************/
  24.  
  25. #include "MiscInfo.h"
  26. #include "Audit.h"
  27. #include "Debug.h"
  28. #include "Definitions.h"
  29.  
  30. #include "LFOListSpecifier.h"
  31. #include "Memory.h"
  32. #include "LFOSpecifier.h"
  33.  
  34.  
  35. struct LFOListSpecRec
  36.     {
  37.         long                                    NumLFOSpecs;
  38.         struct LFOSpecRec**        Array;
  39.     };
  40.  
  41.  
  42. /* allocate a new LFO spec list */
  43. LFOListSpecRec*                NewLFOListSpecifier(void)
  44.     {
  45.         LFOListSpecRec*            LFOListSpec;
  46.  
  47.         LFOListSpec = (LFOListSpecRec*)AllocPtrCanFail(sizeof(LFOListSpecRec),
  48.             "LFOListSpecRec");
  49.         if (LFOListSpec == NIL)
  50.             {
  51.              FailurePoint1:
  52.                 return NIL;
  53.             }
  54.         LFOListSpec->Array = (struct LFOSpecRec**)AllocPtrCanFail(0,"LFOListSpecRec Array");
  55.         if (LFOListSpec->Array == NIL)
  56.             {
  57.              FailurePoint2:
  58.                 ReleasePtr((char*)LFOListSpec);
  59.                 goto FailurePoint1;
  60.             }
  61.         LFOListSpec->NumLFOSpecs = 0;
  62.         return LFOListSpec;
  63.     }
  64.  
  65.  
  66. /* dispose of an LFO spec list and all the specs inside of it */
  67. void                                    DisposeLFOListSpecifier(LFOListSpecRec* LFOListSpec)
  68.     {
  69.         long                                Scan;
  70.  
  71.         CheckPtrExistence(LFOListSpec);
  72.         for (Scan = 0; Scan < LFOListSpec->NumLFOSpecs; Scan += 1)
  73.             {
  74.                 PRNGCHK(LFOListSpec->Array,&(LFOListSpec->Array[Scan]),
  75.                     sizeof(LFOListSpec->Array[Scan]));
  76.                 DisposeLFOSpecifier(LFOListSpec->Array[Scan]);
  77.             }
  78.         ReleasePtr((char*)LFOListSpec->Array);
  79.         ReleasePtr((char*)LFOListSpec);
  80.     }
  81.  
  82.  
  83. /* get a LFOSpecRec out of the list */
  84. struct LFOSpecRec*        LFOListSpecGetLFOSpec(LFOListSpecRec* LFOListSpec, long Index)
  85.     {
  86.         CheckPtrExistence(LFOListSpec);
  87.         ERROR((Index < 0) || (Index >= LFOListSpec->NumLFOSpecs),PRERR(ForceAbort,
  88.             "LFOListSpecGetLFOSpec:  index out of range"));
  89.         PRNGCHK(LFOListSpec->Array,&(LFOListSpec->Array[Index]),
  90.             sizeof(LFOListSpec->Array[Index]));
  91.         return LFOListSpec->Array[Index];
  92.     }
  93.  
  94.  
  95. /* create a new LFO spec entry in the list */
  96. MyBoolean                            LFOListSpecAppendNewEntry(LFOListSpecRec* LFOListSpec,
  97.                                                 struct LFOSpecRec* NewEntry)
  98.     {
  99.         struct LFOSpecRec**    NewArray;
  100.  
  101.         CheckPtrExistence(LFOListSpec);
  102.         NewArray = (struct LFOSpecRec**)ResizePtr((char*)LFOListSpec->Array,
  103.             sizeof(struct LFOSpecRec*) * (LFOListSpec->NumLFOSpecs + 1));
  104.         if (NewArray == NIL)
  105.             {
  106.                 return False;
  107.             }
  108.         LFOListSpec->Array = NewArray;
  109.         LFOListSpec->Array[LFOListSpec->NumLFOSpecs] = NewEntry;
  110.         LFOListSpec->NumLFOSpecs += 1;
  111.         return True;
  112.     }
  113.  
  114.  
  115. /* get the number of elements in the list */
  116. long                                    LFOListSpecGetNumElements(LFOListSpecRec* LFOListSpec)
  117.     {
  118.         CheckPtrExistence(LFOListSpec);
  119.         return LFOListSpec->NumLFOSpecs;
  120.     }
  121.